pod debug方式

前言

這陣子建了一個新環境,
然後pod在第一次啓動時,都會重啓,
但一旦重啓就看不到之前的log。

正文

看上一次的log記錄

kubectl logs {PODNAME} --previous

其他用法

# Return snapshot logs from pod nginx with only one container
kubectl logs nginx

# Return snapshot of previous terminated ruby container logs from pod web-1
kubectl logs -p -c ruby web-1

# Begin streaming the logs of the ruby container in pod web-1
kubectl logs -f -c ruby web-1

# Display only the most recent 20 lines of output in pod nginx
kubectl logs --tail=20 nginx

# Show all logs from pod nginx written in the last hour
kubectl logs --since=1h nginx

ref .

連進去pod裏面監控

有時會碰到這個pod沒有權限可以安裝htop或 top等等,
這些看系統效能的東西,
此時可以透過這種方式,直接外掛一個debug的image,
就能隨便你亂搞了,還不怕會影響到正在執行的pod。

下面指令的意思是,連去 filebeat的pod。
如果要指定container的話,增加 --target=filebeat的指令。

    kubectl debug -it \
    --container=debug-container \
    --image=alpine \
    filebeat-beat-filebeat-bcb666b79-vm6dt

ref.
- Debugging Running Pods on Kubernetes